/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package redes;

/**
 *
 * @author Thiago
 */
public class Cast {
    int i = 0;
    String ipString;
    int ipInt;
    
    public void setIp(String ip){
        this.i = this.ipInt = 0;
        this.ipString = ip; 
        int a1,a2,a3,a4;
        a1 = Integer.parseInt(parte(ipString));
        a2 = Integer.parseInt(parte(ipString));
        a3 = Integer.parseInt(parte(ipString));
        a4 = Integer.parseInt(parte(ipString));
        
        setIp(a1, a2, a3, a4);
    }
    
    private String parte(String pedaco){
        String saida = "";
        for( ; i < ipString.length(); i++){
            if(ipString.charAt(i) == '.')
                break;
            saida += ipString.charAt(i);
        }
        i++;
        return saida;
    }
    
    private void setIp(int a1, int a2, int a3, int a4) {
        this.ipInt = ((a1 & 0xFF) << 24)
                    | ((a2 & 0xFF) << 16)
                    | ((a3 & 0xFF) << 8)
                    | ((a4 & 0xFF) << 0);
    }
    
    public int getIp(){
        return this.ipInt;
    }
}
